package com.example.factory.simple.calculator;

/**
 * 工厂：创建操作数实例
 * <p>
 * 创建哪个实例或者未来会不会增加实例化的对象，都由这个工厂类来做这个创建实例的过程
 */
public class OperationFactory {

    /**
     * 根据操作符创建对应操作数
     *
     * @param op 操作符 +、-、*、/ ...
     * @return
     */
    public static Operation createOperation(String op) {

        Operation operation = null;
        switch (op) {
            case "+":
                operation = new OperationAdd();
                break;
            case "-":
                operation = new OperationSub();
                break;
            case "*":
                operation = new OperationMul();
                break;
            case "/":
                operation = new OperationDiv();
                break;
        }
        return operation;
    }

}
